<?php
/**
+-----------------------------------------------------------------------+
* @autor tonera <tonera at gmail.com>;
* @since 2010/6/8
* @version $Id: update_1.3.7_1.3.8.php,v 1.3.8 tonera$
* @description	此升级程序主要是升级数据库.仅用于1.3.7升级到1.3.8
+-----------------------------------------------------------------------+
*/
error_reporting(0);
session_start();
header("Content-Type: text/html; charset=UTF-8");
include_once(dirname(__FILE__) . "/php/config.inc.php");
include_once(CHINO_PATH . "/Chino.php");
include_once CHINO_MODPATH.'/config/config.inc.php';
include_once CHINO_PHPPATH.'/lang/lang_public.php';
$GLOBALS['adodb'] = Chino::getObject('adodb');
include_once CHINO_LIBPATH.'/db_mysql.inc.php';
$GLOBALS['adodb']->debug	= false;

$wow_cfg_lang	= empty($_COOKIE['wow_cfg_lang'])?"zh-cn":$_COOKIE['wow_cfg_lang'];
if(!array_key_exists($wow_cfg_lang, $langTypeArray)) exit('Error cookie.');
include_once(CHINO_PHPPATH .  "/lang/".$wow_cfg_lang."/inslang.inc.php");

if(empty($_SESSION['wowdkp']['user']) or !$_SESSION['wowdkp']['usertype'] or $_SESSION['wowdkp']['dkptable']!=TABLEHEAD or $_SESSION['wowdkp']['db']!=DBNAME) {
	exit("请以管理员身份登录后再执行升级程序.(Please login with administrator to run the script.)");
}


if(!empty($_POST['update']) ){
	$sql	= "select a.id as id, b.name as aname from ".TABLEHEAD."_item  as a left join ".TABLEHEAD."_itemproperty as b on a.ipid=b.id where b.name!=''";
	$link	= $GLOBALS['adodb']->connect(DBHOST, DBUSER, DBPASS, DBNAME);
	if(!$link) {
		exit("数据库错误.(Database error.)");
	}
	$mysqlvrs		= $GLOBALS['adodb']->execute("select version()");
	$mysqlversion	= $mysqlvrs->fields[0];
	if($mysqlversion > '4.1') {
		$GLOBALS['adodb']->execute("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary");
		if($mysqlversion > '5.0.1') {
			$GLOBALS['adodb']->execute("SET sql_mode=''");
		}
	}
	$rs		= $GLOBALS['adodb']->execute($sql);
	while(!$rs->EOF) {
		@preg_match("/\|\|([0-9]*):/i", $rs->fields['aname'], $match);
		$itemId		= (int)$match[1];
		if(empty($itemId)) continue;
		$id			= $rs->fields['id'];
		$sql		= "update ".TABLEHEAD."_item set ipid='$itemId' where id='$id'";
		//echo($sql."<br>");
		$GLOBALS['adodb']->execute($sql);
		$rs->MoveNext();
	}

	if(!$rs) {
		echo("Error: can't update.");
	}else {
		echo("升级成功，请删除此升级文件.(OK! Please delete the file.)");
	}
	exit;
}else {
	echo("<h3><font color=\"red\">点击升级按钮开始升级(Click the button to update)</font></h3>");
}
?>
<html>
<body>
<br />
<hr />
<form method=post action="">
	<input type="submit" name="update" value="升级到(Update)1.3.8">
</form>
</body>
</html>




